package com.jcommander;

import java.awt.Dimension;
import java.util.Locale;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import org.jdesktop.swingx.JXTreeTable;

import com.jcommander.gui.GUIBuilder;
import com.jcommander.gui.locale.ResourceBundler;
import com.jgoodies.looks.LookUtils;
import com.jgoodies.looks.Options;


public class JCommander {

	private static final JFrame frame = new JFrame("JCommander");
	private final GUIBuilder guiBuilder = new GUIBuilder();
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		configureUI();
		//TODO tutaj wstaw locale jak bedziesz dorabial
        UIManager.getDefaults().put("OptionPane.yesButtonText", "Tak");
        UIManager.getDefaults().put("OptionPane.noButtonText", "Nie");
        UIManager.getDefaults().put("OptionPane.cancelButtonText", "Anuluj");
        final JCommander jcommander = new JCommander();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                jcommander.setVisible(true);
            }
        });
        
        
	}
	
	public static void exitApplication() {
		//TODO here free all resources
		frame.dispose();
		
	}
	
	private JCommander() {
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(800, 600);
		frame.getContentPane().add(guiBuilder.createMainPanel());
		ResourceBundler.getInstance().setLocale(new Locale("PL"));
	}
	
	private void setVisible(boolean value) {
		frame.setVisible(value);
	}
	
	 /**
     * Configures the UI; tries to set the system look on Mac, 
     * <code>WindowsLookAndFeel</code> on general Windows, and
     * <code>Plastic3DLookAndFeel</code> on Windows XP and all other OS.<p>
     * 
     * The JGoodies Swing Suite's <code>ApplicationStarter</code>,
     * <code>ExtUIManager</code>, and <code>LookChoiceStrategies</code>
     * classes provide a much more fine grained algorithm to choose and
     * restore a look and theme.
     * 
     * @author Karsten Lentzsch
     */
    private static void configureUI() {
        UIManager.put(Options.USE_SYSTEM_FONTS_APP_KEY, Boolean.TRUE);
        Options.setDefaultIconSize(new Dimension(18, 18));

        String lafName =
            LookUtils.IS_OS_WINDOWS_XP
                ? Options.getCrossPlatformLookAndFeelClassName()
                : Options.getSystemLookAndFeelClassName();

        try {
            UIManager.setLookAndFeel(lafName);
        } catch (Exception e) {
            System.err.println("Can't set look & feel:" + e);
        }
    }

	public static JFrame getFrame() {
		return frame;
	}


}
